package n1088;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	static int f[][] = new int[101][101];

	static int a[][] = new int[101][101];

	static int max, R, C;

	static void init() {
		for (int i = 0; i < R; i++)
			for (int j = 0; j < C; j++)
				f[i][j] = -1;
	}

	static int get(int m, int n) {
		if (m < 0 || m >= R || n < 0 || n >= C)
			return 0;

		if (f[m][n] != -1)
			return f[m][n];

		int f1 = 0, f2 = 0, f3 = 0, f4 = 0;
		if (m - 1 >= 0 && m - 1 < R && n >= 0 && n < C && a[m-1][n]<a[m][n]) {
			// 上
			f1 = get(m - 1, n)+1;
		}

		if (m >= 0 && m < R && n + 1 >= 0 && n + 1 < C && a[m][n+1]<a[m][n]) {
			f2 = get(m, n + 1)+1;
		}

		if (m + 1 >= 0 && m + 1 < R && n >= 0 && n < C&& a[m+1][n]<a[m][n]) {
			f3 = get(m + 1, n)+1;
		}

		if (m >= 0 && m < R && n - 1 >= 0 && n - 1 < C&& a[m][n-1]<a[m][n]) {
			f4 = get(m, n - 1)+1;
		}

		f[m][n] = Math.max(Math.max(f1, f2), Math.max(f3, f4));

		return f[m][n];
	}

	static int solve() {
		max = 0;
		for (int i = 0; i < R; i++)
			for (int j = 0; j < C; j++) {
				int t = get(i, j);
				if (max < t) {
					max = t;
				}
			}
		return max+1;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		Scanner cin=new Scanner(bf);
		R=cin.nextInt();
		C=cin.nextInt();
		for(int i=0;i<R;i++)
			for(int j=0;j<C;j++)
				a[i][j]=cin.nextInt();
		init();
		System.out.println(solve());
	}

}
